package com.example.xiongmao.controller;

import com.example.xiongmao.entity.DTO.CommonStatus;
import com.example.xiongmao.entity.DTO.admin.addAdminDTO;
import com.example.xiongmao.entity.DTO.admin.adminChargeDTO;
import com.example.xiongmao.entity.DTO.shopmanager.ShopManagerDTO;
import com.example.xiongmao.entity.DTO.shopmanager.addShopManagerDTO;
import com.example.xiongmao.entity.PageResult;
import com.example.xiongmao.entity.Result;
import com.example.xiongmao.entity.VO.admin.adminChargeVO;
import com.example.xiongmao.entity.VO.shopmanager.ShopManagerChargeVO;
import com.example.xiongmao.service.ShopManagerChargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shopManager")
public class ShopManagerController {

    @Autowired
    private ShopManagerChargeService shopManagerChargeService;

    // 分页条件查询
    @GetMapping
    public Result<PageResult> list(ShopManagerDTO shopManagerDTO){
        PageResult pageResult = shopManagerChargeService.list(shopManagerDTO);
        System.out.println("page:"+shopManagerDTO.getPage()+"pageSize"+shopManagerDTO.getPageSize());
        return Result.success(pageResult);
    }

    // 新增用户
    @PostMapping
    public Result addAdmin(@RequestBody addShopManagerDTO addShopManager){
        shopManagerChargeService.add(addShopManager);
        return Result.success();
    }

    // 编辑回显
    @GetMapping("/{id}")
    public Result getByShopManagerId(@PathVariable Integer id){
        ShopManagerChargeVO shop_manages = shopManagerChargeService.getbyId(id);
        return Result.success(shop_manages);
    }

    // 编辑用户信息
    @PutMapping
    public Result updateShopManager(@RequestBody addShopManagerDTO addShopManager){
        System.out.println("前端传回来的："+addShopManager);
        shopManagerChargeService.updateShopManager(addShopManager);
        return Result.success();
    }

    // （批量）删除用户信息
    @DeleteMapping
    public Result deleteShopManager(@RequestParam List<Integer> ids){
        System.out.println("当前要删除的ids:"+ids);
        shopManagerChargeService.deleteShopManagerBatch(ids);
        return Result.success();
    }

    // 禁用用户状态
    @PutMapping("/status")
    public Result ShopManagerStatusChange(@RequestBody CommonStatus shopManagerStatus){
        System.out.println("当前要修改状态的id:"+shopManagerStatus);
        shopManagerChargeService.shopManagerStatusChange(shopManagerStatus);
        return Result.success();
    }
}
